//
//  LCCouponAdvertViewController.m
//  lechuang
//
//  Created by Mr_hi on 2023/4/4.
//  Copyright © 2023 Mooyi. All rights reserved.
//

#import "LCCouponAdvertViewController.h"
#import "LCCouponCollectionHeaderView.h"
#import "LCGouponCollectionViewCell.h"

#import "LCCouponService.h"
#import "LCCouponLinkModel.h"

#import "XWXAllXieYiController.h"

@interface LCCouponAdvertViewController ()<UICollectionViewDelegateFlowLayout, UICollectionViewDataSource>

@property (weak, nonatomic) IBOutlet UICollectionView *collectionView;

@property (strong, nonatomic)NSArray * dataArr;

@end

@implementation LCCouponAdvertViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self getLinkData];
}

- (void)getLinkData {
    [LCCouponService getCouponHeadItemWithGroupname:self.groupname Block:^(BOOL isSuccess, NSArray<LCCouponLinkModel *> *list) {
        if (isSuccess) {
            self.dataArr = list;
            [self.collectionView reloadData];
        }
    }];
}

- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
    return UIEdgeInsetsMake(0, 5, 0, 5);
}

-(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
    return 0;
}

-(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
    return 0;
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return self.dataArr.count;
}

-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    CGFloat headCellW = (ScreenW - 10)/5;
    return CGSizeMake(headCellW, 90);
}

-(__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    LCCouponHeaderViewCollectionCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"LCCouponHeaderViewCollectionCell" forIndexPath:indexPath];
    LCCouponLinkModel * link = self.dataArr[indexPath.item];
    cell.iconView.hidden = NO;
    [cell.iconView sd_setImageWithURL:[LCFunction XWX_URLImg:link.linksthumb]];
    cell.nameLb.text = link.linksname;
    return cell;
}

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    LCCouponLinkModel * link = self.dataArr[indexPath.item];
    
    XWXAllXieYiController *webVC = [XWXAllXieYiController new];
    webVC.tileStr = link.linksname;
    webVC.urlStr = link.linksurl;
    webVC.isPushFrom = YES;
    webVC.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:webVC animated:YES];
}

@end
